'use strict';
app.controller('agentAreaCtrl',['$scope','utilService','$modal', function($scope, utilService, $modal){
    $scope.agentArea = {};
    // call server.
    $scope.query = function(){
        utilService.queryForPagingList($scope,{
            url:$scope.app.domainAgent + 'manage/agentArea/list',
            params:$scope.agentArea
        }).then(function(result){

        });
    }
    $scope.query();

    //新增代理区域窗口
    $scope.openAdd = function () {
        var modalInstance = $modal.open({
            templateUrl: 'agentAreaAdd.html',
            controller: 'agentAreaAddCtrl',
            scope:$scope,
            resolve: {
                items: function () {
                    return  $scope;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) {
            console.log($scope.selected = selectedItem);
            $scope.selected = selectedItem;
        }, function () {
            console.info('Modal dismissed at: ' + new Date());
        });
    };

    // 删除
    $scope.openDelete = function(id, name){
        $scope.modal = {
            title: "删除代理区域",
            message: "您是否要删除'"+ name +"'?"
        }

        utilService.modal($modal, $scope, {
            title: $scope.modal.title,
            controller: "agentAreaDeleteCtrl",
            message: $scope.modal.message,
            data:{
                id: id
            }
        });
    }

    //修改
    $scope.openEdit = function(id, name, level){
        $scope.editData = {
            id: id,
            name: name,
            level: level
        };

        var modalInstance = $modal.open({
            templateUrl: 'tpl/agent/agent_area_edit.html',
            controller: 'agentAreaEditCtrl',
            scope:$scope,
            resolve: {
                data:function(){
                    return $scope;
                }
            }
        });

        modalInstance.result.then(function (result) {
            console.log(result);
        }, function () {
            console.info('Modal dismissed at: ' + new Date());
        });
    };
}]);
